package com.first.agent.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.first.agent.common.JsonResult;
import com.first.agent.service.RoleService;
import com.first.agent.service.impl.RoleServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
/*
角色管理——查看页面
 */
@WebServlet("/role/list")
public class QueryRoleServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer currentPage = Integer.parseInt(request.getParameter("page"));
        Integer pageSize = Integer.parseInt(request.getParameter("limit"));
        System.out.println(currentPage);
        System.out.println(pageSize);
        RoleService roleService = new RoleServiceImpl();
        JsonResult jsonResult = roleService.queryRoleList(currentPage, pageSize);
        System.out.println(jsonResult);
        //查询的数据转成json格式返回
        response.setContentType("application/json;charset=utf-8");
        PrintWriter pw = response.getWriter();
        pw.write(JSONObject.toJSONString(jsonResult));
        pw.flush();
        pw.close();
    }
}
